Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
Go to another page without refresh [Django]

How to achieve going to another page without refreshing after for example clicking a link to another URL. More examples, I have a list of books display and when I clicked on one of the book, it will redirect me to the selected book page. This is the example of the code link. <a class="link" href="{% url 'books:view_book_detail' obj.book.name obj.pk %}">View book</a>

I know about the history.pushState() but how to actually use it ? Can it be use with URL from Django. Are there any method else then stated ?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Using regular django or plain javascript is not efficient enough for this purpose.

Modern JavaScript frameworks like React, Angular, Vue etc are typically used for these case scenarios.

But still, it's not impossible though to do this without JS frameworks. One of the approaches that you can use is using AJAX.

You can create a base.html which will be our basic template, and then break the application into little components like home.html, product-list.html, view-product.html. Which we can further include according to our requirements.

{% include 'view-product.html' with product=product_object %}
(something like this)

Make an AJAX request to /view_product/<id>/ which should return a JsonResponse about which component to display. And through JavaScript, we can handle loading that specific component.

But again, THIS IS NOT A GOOD PRACTICE, I would recommend using JavaScript frameworks for Single Page Applications.

about 4 years ago · Juan Pablo Isaza Relatório

0

I did this using many if statements in view.py
you need to use <button type="button"> instead of <a> , and check if the POST request has that name to respond with different context, also you need to use if statements in template to update the frontend according to the response
IT IS A BAD PRACTICE, it is highly recommended to use JS framework to have a single page app

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda